import java.util.concurrent.CountDownLatch;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by rzd on 2017/4/2.
 */
public class Main {
    static ReentrantLock lock=new ReentrantLock(true);
    static CountDownLatch start=new CountDownLatch(1);
    static int n=0;
    public static void main(String[] args) {
        Runnable runnable=new Runnable() {
            @Override
            public void run() {
                while (true)
                {
                    try {
                        start.await();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    lock.lock();

                    try {
                        if(n==60)return;
                        else
                        {
                            for (int i = 0; i < 5; i++) {
                                n++;
                                System.out.println(Thread.currentThread().getName()+" "+n);
                            }
                        }
                    }finally {
                        lock.unlock();
                    }
                }
            }
        };
        new Thread(runnable,"A").start();
        new Thread(runnable,"B").start();
        new Thread(runnable,"c").start();
start.countDown();
    }
}
